package com.hyh.toyshopping.mapper;

import com.hyh.toyshopping.model.Comment;
import com.hyh.toyshopping.model.Toy;
import com.hyh.toyshopping.model.view.CommentView;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @version 1.0
 * @BelongsProject:IntelliJ IDEA
 * @BelongsPackage:com.hyh.toyshopping.mapper
 * @Author:hyhWTX
 * @ClassName:ToyMapper
 * @CreateTime:2022年-12月-14日 20:10
 * @Description: 持久层注解，将当前接口的实现类交个Spring管理tbl_toy表的操作接口
 */
@Repository
public interface ToyMapper {
    /***
     * @Description: 查询所有玩具信息
     * @return List<Toy>

     */
    public List<Toy> queryToyAll(int toy_is_display);

    @Select("select * from tbl_toy where toy_id=#{toy_id}")
    Toy getToyById(int book_id);

    @Select("select c.comment_id,u.user_name,c.comment_message,c.comment_time from tbl_comment c inner join tbl_user u on c.user_id where c.toy_id=#{toy_id} order by c.comment_time desc")
    List<CommentView> getToyComment(int toy_id);

    @Insert("insert into tbl_comment values(default,#{user_id},#{toy_id},#{comment_message},now())")
    void addToyComment(Comment comment);
    @Update("update tbl_toy set toy_is_display=#{toy_is_display} where toy_id=#{toy_id}")
    void updateToyDisplayStatus(@Param("toy_id") int toy_id, @Param("toy_is_display") int toy_is_display);
}
